const Sequelize = require('sequelize')
const {
    MYSQL_CONF
} = require('../conf/db')
const {
    isProd,isTest
} = require('../utils/env')
const {
    host,
    database,
    user,
    password
} = MYSQL_CONF

let conf = {
    host,
    dialect: 'mysql'
}
if(isTest) {
    conf.logging = () =>{}
}
//线上环境
if (isProd) {
    conf.pool = {
        max: 5, //连接池最大连接数量
        min: 0, //最小
        idle: 10000 //10s内没被使用，则释放
    }
}
//创建
const seq = new Sequelize(database, user, password, conf)


module.exports = seq